#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
用户领域模型

定义用户领域的核心业务实体
"""

from datetime import datetime
from typing import Optional, Dict, Any, List


class User:
    """用户模型类"""
    
    def __init__(self, 
                 user_id: str = None, 
                 username: str = None, 
                 password: str = None,
                 email: Optional[str] = None,
                 name: Optional[str] = None,
                 age: Optional[int] = None,
                 gender: Optional[str] = None,
                 address: Optional[str] = None,
                 phone: Optional[str] = None,
                 birthday: Optional[str] = None,
                 company: Optional[str] = None,
                 job: Optional[str] = None,
                 website: Optional[str] = None,
                 token: Optional[str] = None,
                 created_time: Optional[str] = None,
                 updated_time: Optional[str] = None,
                 id: Optional[str] = None):
        """初始化用户对象
        
        Args:
            user_id: 用户ID (业务ID)
            username: 用户名
            password: 密码
            email: 邮箱
            name: 姓名
            age: 年龄
            gender: 性别
            address: 地址
            phone: 电话
            birthday: 生日
            company: 公司
            job: 职位
            website: 网站
            token: 令牌
            created_time: 创建时间
            updated_time: 更新时间
            id: 数据库ID
        """
        self.id = id
        self.user_id = user_id
        self.username = username
        self.password = password
        self.email = email
        self.name = name
        self.age = age
        self.gender = gender
        self.address = address
        self.phone = phone
        self.birthday = birthday
        self.company = company
        self.job = job
        self.website = website
        self.token = token
        self.created_time = created_time or datetime.now().isoformat()
        self.updated_time = updated_time or datetime.now().isoformat()
    
    @classmethod
    def from_row(cls, row):
        """从数据库行创建用户对象
        
        Args:
            row: 数据库查询结果行
            
        Returns:
            User: 用户对象或None
        """
        if not row:
            return None
            
        return cls(
            id=row[0],
            user_id=row[1],
            username=row[2],
            password=row[3],
            email=row[4],
            name=row[5],
            age=row[6],
            gender=row[7],
            address=row[8],
            phone=row[9],
            birthday=row[10],
            company=row[11],
            job=row[12],
            website=row[13],
            token=row[14],
            created_time=row[15],
            updated_time=row[16]
        )
    
    def to_dict(self, exclude_fields: List[str] = None) -> Dict[str, Any]:
        """将用户对象转换为字典
        
        Args:
            exclude_fields: 要排除的字段列表
            
        Returns:
            Dict[str, Any]: 用户数据字典
        """
        exclude_fields = exclude_fields or ['password', 'id']
        result = {}
        
        for key, value in self.__dict__.items():
            if key not in exclude_fields:
                result[key] = value
                
        return result 